<?php
/**
 * Created by PhpStorm.
 * User: koastal
 * Date: 2016/5/15
 * Time: 15:09
 */
require_once("config.php");
require_once("Loader.php");
require_once("functions.php");

define('PG_DEBUG'     , TRUE); // 开启调试模式
// 系统分隔符
define('PG_DS' ,'/');
// 框架核心目录所在位置
define('PG_IN'  ,  dirname(__FILE__).PG_DS);
// 工具类文件所在目录
define('PG_TOOLS', 'tools');

// 页面后缀
if(!defined('PG_SUFFIX')){define('PG_SUFFIX' , false);}
// 站点首页配置
define('PG_INDEX_FILE_NAME' , 'index.php');
define('PG_SROOT', str_replace(PG_INDEX_FILE_NAME, '', $_SERVER['PHP_SELF']));
define('PG_START_TIME'      ,  microtime(true));
// 语言包文件所在目录
define('PG_LANG_PACKAGE', 'lang');
if(isset($_SERVER['PATH_INFO'])){
    $path = isset($_SERVER['PATH_INFO'])? $_SERVER['PATH_INFO']:null;
}else{
    $path = $_SERVER['REQUEST_URI'];
}
$path_array = explode("/",$path);
$path_array = array_slice($path_array,1,3);
$controller = '';
$function = '';
if(count($path_array)<2){
    //访问首页
    if(count($path_array)==1){
        $controller = $path_array[0];
        $function = "index";
    }else{
        $controller = "index";
        $function = "index";
    }
}else{
    //判断$function变量里面有没有？传参
    if(strpos($path_array[2],'?') !== false){
        $path_function=explode('?',$path_array[2])[0];
    }else{
        $path_function=$path_array[2];
    }
    $controller = isset($path_array[0]) ? ucfirst($path_array[0])."_".ucfirst($path_array[1])."Controller" : "Index";
    $function = $path_function ? $path_function : "index";
}
$controller_obj = new $controller;
$controller_obj->$function();
?>